// pages/trun/turn.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 数据格式固定，前两个的zIndex必须是最高的和第二高
    imgArr: [
      { src: "/photos/微信图片_20190821001019.jpg", isturn: false, zIndex: 4 },
      { src: "/photos/微信图片_201908210010191.jpg", isturn: false, zIndex: 3 },
      { src: "/photos/微信图片_201908210010192.jpg", isturn: false, zIndex: 1 },
      { src: "/photos/微信图片_201908210010193.jpg", isturn: false, zIndex: 1 },
      { src: "/photos/微信图片_201908210010194.jpg", isturn: false, zIndex: 1 },
      { src: "/photos/微信图片_201908210010194.jpg", isturn: false, zIndex: 1 },
      { src: "/photos/微信图片_201908210010194.jpg", isturn: false, zIndex: 1 },
    ],
    flag:true
  },
  setclass: function (e) {
    if(this.data.flag){
      this.data.flag=false;
      let imgs = this.data.imgArr;

      let index = e.currentTarget.dataset.index;
      imgs.map((ele,i)=>{
        if (index == i) {
          imgs[i].isturn = !imgs[i].isturn;
          imgs[i].zIndex = 4;

        } else {
          imgs[i].zIndex = 1;
        }
      });
      if (index - 1 >= 0) {
        imgs[index - 1].zIndex = 3;
      }
      if (index + 1 < imgs.length) {
        imgs[index + 1].zIndex = 3;
      }
      if (index - 2 >= 0) {
        imgs[index - 2].zIndex = 2;
      }
      if (index + 2 < imgs.length) {
        imgs[index + 2].zIndex = 2;
      }
      this.setData({
        imgArr: imgs,
      })
    }



  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  start(){
    console.log('动画开始')
  },
  end(e){
    this.data.flag=true
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  // onShow: function () {
  //   this.selectComponent('#music').onShow()
  // },
  // onHide: function () {
  //   this.selectComponent('#music').onHide()
  // },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})